package intermedia;

import java.util.Hashtable;
import java.util.Set;

import semantica.TypeAttribute;
import semantica.ValidAttributes;

public class Attributes {

	public Hashtable<String, String> attributes;
	public ValidAttributes att;

	public Attributes() {
		attributes = new Hashtable<String, String>();
		att = new ValidAttributes();
	}

	public void addAtributes(Attributes _attributes) {
		Set<String> keys = _attributes.attributes.keySet();
		for (String key : keys)
			attributes.put(key, _attributes.attributes.get(key));
	}

	public void addAtribute(String _key, String _val, int line, int column) throws InvalidTypeAttributeException {

		if (!att.getAtttype().contains(_key)) {
			System.out.println("Warning! Unknown Attribute at line " + line
					+ ", column " + column + "!");
		} else {
			TypeAttribute t = att.get(_key);
			if (!t.validate(_val))
				throw new InvalidTypeAttributeException(line, column);
		}
		attributes.put(_key, _val);
	}
	
	public void addAtribute(String _key, String _val) throws InvalidTypeAttributeException {

		if (!att.getAtttype().contains(_key)) {
			System.out.println("Warning! Unknown Attribute!");
		} else {
			TypeAttribute t = att.get(_key);
			if (!t.validate(_val))
				throw new InvalidTypeAttributeException();
		}
		attributes.put(_key, _val);
	}
}
